//页面白名单
const whiteList = [
	'pages/login/login',
]
import store from '../store/index.js'

function hasPermission(url) {
	//请求路径在白名单中直接跳转，或者带有token直接跳转，
	for (var i = 0; i < whiteList.length; i++) {
		if (url.indexOf(whiteList[i]) != -1 || store.state.user.token) {
			return true
		}
	}
	return false
}


uni.addInterceptor('navigateTo', {
	invoke(e) {
		if (!hasPermission(e.url)) {
			store.commit('user/updateRedirectInfo', e.url)
			uni.navigateTo({
				url: '../../pages/login/login'
			})
			uni.$showMsg('请先登录!')
			return false
		}
		return true
	},
})
